package com.mjkj.demo.utils;

/**
 * @author cwh
 * @date 2023/2/12
 **/
public class SecondToStringUtils {
    /**
     * 时间转换
     * @param seconds 秒数
     * @return 时分秒字符串
     */
    public static String transformLastTime(Integer seconds) {
        if (seconds >= 0 && seconds < 60) {
            return seconds + "s";
        } else if (seconds >= 60 && seconds < 3600) {
            int changeM = (int) Math.floor(seconds / 60);
            int surplusM = (int) Math.floor(seconds % 60);
            if (surplusM > 0) {
                return changeM + "m" + surplusM + "s";
            } else {
                return changeM + "m";
            }
        } else if (seconds >= 3600) {
            int changeH = (int) Math.floor(seconds / 3600);
            int surplusH = (int) Math.floor(seconds % 3600);
            if (surplusH >= 60) {
                int changeM = (int) Math.floor(surplusH / 60);
                int surplusM = (int) Math.floor(surplusH % 60);
                if (surplusM > 0) {
                    return changeH + "h" + changeM + "m" + surplusM + "s";
                } else {
                    return changeH + "h" + changeM + "m";
                }
            } else if (surplusH < 60 && surplusH > 0) {
                int surplusM = (int) Math.floor(surplusH % 1024);
                return changeH + "h" + surplusM + "s";
            } else {
                return changeH + "h";
            }
        }
        return " ";
    }
}
